<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Warehouses</title>
    </h:head>
    <f:view beforePhase="#{UserDisplayManagedBean.doDisplay}">
        <f:view beforePhase="#{WarehouseManagedBean.initView}">
            <h:body>
                <h:form prependId="false">
                    <p:growl id="growl" showDetail="true" />  
                    <p:growl id="notif" showDetail="true"/>  
                    <p:poll interval="5"   
                            actionListener="#{MessageManagedBean.checkNewMessage}" immediate="true" update="notif" />
                    <div id="top" class="top">
                        <h:graphicImage value="/image/newHeader.jpg"/>
                    </div>
                    <div id="content">

                        <table >
                            <tr><td>
                                    <p:toolbar style="background-color:darkred;font-size:70%;height:25px;width:100%"> 
                                        <p:toolbarGroup align="right">
                                            <p:button title="Home" image="ui-icon-home" outcome ="InventoryDeptWorkspace"/>                                  
                                            <p:button title="Notes" image="ui-icon-note" outcome="tasks"/>                                    
                                            <p:button title="Mail" outcome="messages"  image="ui-icon-mail-closed" />                                   
                                            <p:button title="Edit Preferences" image="ui-icon-gear"/>                                   
                                            <p:button title="Help" image="ui-icon-help"/>
                                            <p:commandButton title="Log Out" immediate="true" type="submit" image="ui-icon-close" actionListener="#{UserManagedBean.doLogout}"/> 
                                        </p:toolbarGroup>
                                    </p:toolbar></td>
                                <td>
                                    <h:graphicImage value="warehouse.gif" style="width:35px;height:35px" />
                                    <h:outputText value="         "/>
                                    <h:outputText value="Warehouses" style="font-family:Tahoma;font-size:20px;font-weight:bolder"/>
                                    <p:spacer width="100" height="10"/>
                                </td>
                            </tr>
                            <tr>

                                <td style="vertical-align:top">
                                    <p:menu style="width:200px;font-size: 12px;font-family: Tahoma;border-style: ridge">  
                                        <p:submenu label="Inventories" > 
                                            <p:menuitem value="New Product" url="http://localhost:8080/MerlionERP-war/SCM/addProduct.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>  
                                            <p:menuitem value="View All Products" url="http://localhost:8080/MerlionERP-war/SCM/products.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>  
                                            <p:menuitem value="New Material" url="http://localhost:8080/MerlionERP-war/SCM/addMaterial.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>                                      
                                            <p:menuitem value="View All Materials" url="http://localhost:8080/MerlionERP-war/SCM/materials.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                            <p:menuitem value="View Unhoused Inventories" url="http://localhost:8080/MerlionERP-war/SCM/unhousedInventories.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                            <p:menuitem value="View Inventory Movements" url="http://localhost:8080/MerlionERP-war/SCM/inventoryMovements.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />

                                        </p:submenu>
                                        <p:submenu label="Warehouses" >
                                            <p:menuitem value="New Warehouse" url="http://localhost:8080/MerlionERP-war/SCM/addWarehouse.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>        
                                            <p:menuitem value= "View All Warehouses" url="http://localhost:8080/MerlionERP-war/SCM/warehouses.xhtml" ajax="false" icon="ui-icon ui-icon-tag" />
                                        </p:submenu>
                                        <p:submenu label="Shipments and Orders">
                                            <p:menuitem value="Delivery Orders" url="http://localhost:8080/MerlionERP-war/SCM/deliveryOrders.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>
                                            <p:menuitem value="Picking Orders" url="http://localhost:8080/MerlionERP-war/SCM/pickingOrders.xhtml" ajax="false" icon="ui-icon ui-icon-tag"/>            
                                        </p:submenu>
                                    </p:menu>
                                    <p:calendar mode="inline" style="font-size:11px;font-family:Tahoma"/>
                                </td>

                                <td style="vertical-align:top">

                                    <p:toolbar style="background-color:  #d9bb73;font-size: 70%;width:99.5%"> 
                                        <p:toolbarGroup align="left">  
                                            <p:button value="New Warehouse" outcome="addWarehouse" image="ui-icon-plus"/>
                                            <p:commandButton value="Delete" title="Delete" image="ui-icon ui-icon-trash" oncomplete="warehouseDialog.show()"/>                                   

                                        </p:toolbarGroup>  
                                    </p:toolbar> 

                                    <p:dataTable id="panel" 
                                                 var="warehouses" value="#{WarehouseManagedBean.warehouses}"                       
                                                 paginator="true" rows="5"  
                                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                                 rowEditListener="#{WarehouseManagedBean.onEditRowWarehouse}"
                                                 rowsPerPageTemplate="5,10,15"  style="font-size:60%;width:100%"
                                                 selection="#{WarehouseManagedBean.selectedWarehouses}"
                                                 emptyMessage="No data found with given criteria" widgetVar="warehouseTable">  

                                        <f:facet name="header">                           
                                            <p:outputPanel style="text-align:right"  >
                                                <h:outputText value="Search all fields:" style="margin-left:840px" />  
                                                <p:inputText id="globalFilter" onkeyup="warehouseTable.filter()" style="right:-100px;width:150px" />  
                                            </p:outputPanel>
                                        </f:facet> 

                                        <p:column selectionMode="multiple"/> 
                                        <!--style="border-left-color:transparent;border-right-color:transparent"/-->

                                        <p:column headerText="View" style="width:16px;border-right-color:transparent" >  
                                            <p:rowToggler />  
                                        </p:column> 

                                        <p:column headerText="Edit" style="width:20px;border-left-color:transparent;border-right-color:transparent">    
                                            <p:rowEditor/> 
                                        </p:column>


                                        <p:column headerText ="Del." style="width: 16px;border-left-color:transparent">  
                                            <!--DELETE-->
                                            <p:commandButton title="Delete" image="ui-icon ui-icon-trash" ajax="true" immediate="true"
                                                             update="panel" oncomplete="warehouseDialog.show()">
                                                <f:setPropertyActionListener target="#{WarehouseManagedBean.selectedWarehouse}"
                                                                             value="#{warehouses}"/>
                                            </p:commandButton>
                                        </p:column>


                                        <!--Warehouse ID-->
                                        <p:column sortBy="#{warehouses.id}" filterBy="#{warehouses.id}" filterMatchMode="contains"
                                                  filterStyle="width:50px">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->
                                            <f:facet name="header">
                                                <h:outputText value="ID"/>
                                            </f:facet>
                                            <h:outputText value="#{warehouses.id}"/>
                                        </p:column>

                                        <!--Warehouse Name-->
                                        <p:column headerText="Warehouse Name" sortBy="#{warehouses.name}" filterBy="#{warehouses.name}" 
                                                  filterMatchMode="contains">

                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{warehouses.name}" />  
                                                </f:facet>  
                                                <f:facet name="input">
                                                    <p:inputText value="#{warehouses.name}" style="width:100%"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>   

                                        <!--Warehouse Capacity-->
                                        <p:column headerText="Capacity" sortBy="#{warehouses.name}" filterBy="#{warehouses.name}" 
                                                  filterStyle="width:80px" filterMatchMode="contains">

                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{warehouses.capacity}" />  
                                                </f:facet>  
                                                <f:facet name="input">
                                                    <p:inputText value="#{warehouses.capacity}" style="width:100%"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>   

                                        <!--Address-->
                                        <p:column headerText="Street Address" sortBy="#{warehouses.street}" 
                                                  filterBy="#{warehouses.street}" filterMatchMode="contains">

                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{warehouses.street}" />  
                                                </f:facet>
                                                <f:facet name="input">
                                                    <p:inputText value="#{warehouses.street}" style="width:100%" />
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  

                                        <!--City-->
                                        <p:column headerText="Country" sortBy="#{warehouses.city}" 
                                                  filterBy="#{warehouses.city}" filterMatchMode="contains">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{warehouses.city}" />  
                                                </f:facet>
                                                <f:facet name="input"> 
                                                    <p:inputText value="#{warehouses.city}"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  


                                        <!--Country-->
                                        <p:column headerText="Country" sortBy="#{warehouses.country}" 
                                                  filterBy="#{warehouses.country}" filterMatchMode="contains">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{warehouses.country}" />  
                                                </f:facet>
                                                <f:facet name="input"> 
                                                    <p:inputText value="#{warehouses.country}"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  

                                        <!--Country-->
                                        <p:column headerText="Postal Code" sortBy="#{warehouses.postcode}" 
                                                  filterBy="#{warehouses.postcode}" filterMatchMode="contains">
                                            <!--style="border-left-color:transparent;border-right-color:transparent"-->  
                                            <p:cellEditor>
                                                <f:facet name="output">  
                                                    <h:outputText value="#{warehouses.postcode}" />  
                                                </f:facet>
                                                <f:facet name="input"> 
                                                    <p:inputText value="#{warehouses.postcode}"/>
                                                </f:facet>
                                            </p:cellEditor>
                                        </p:column>  



                                        <p:column style="width:32px">  
                                            <p:commandLink update="display1" oncomplete="editDialog.show()" title="Edit Details">  
                                                <p:graphicImage value="clipboard.png" style="width:20px;height:20px"/>
                                                <f:setPropertyActionListener value="#{warehouses}" target="#{WarehouseManagedBean.selectedViewWarehouse}" />  
                                                <f:setPropertyActionListener value="#{true}" target="#{WarehouseManagedBean.editMode}" />  
                                            </p:commandLink>                                                                
                                        </p:column>

                                        <p:column style="width:32px">
                                            <p:commandButton value="View Warehouse Inventory" update="warehouseInventory " oncomplete="inventoryDialog.show()" title="View Warehouse Inventory">
                                                <f:setPropertyActionListener value="#{warehouses}" target="#{WarehouseManagedBean.selectedViewWarehouse}"/>
                                            </p:commandButton>
                                        </p:column>



                                        <p:rowExpansion>  
                                            <h:panelGrid id="display" columns="6" cellpadding="3"
                                                         style="font-family:Tahoma; font-size:10px;border-color:transparent;column-rule-style:hidden">

                                                <h:outputText value="Warehouse Id" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.id}" />

                                                <h:outputText value="Warehouse Name" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.name}" /> 

                                                <h:outputText value="Warehouse Capacity" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.capacity}" /> 

                                                <h:outputText value="Street Address" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.street}" />  

                                                <h:outputText value="City" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.city}" /> 

                                                <h:outputText value="Country" />  
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.country}" />

                                                <h:outputText value="Postal Code" />
                                                <h:outputText value=":"/>
                                                <h:outputText value="#{warehouses.postcode}" />


                                            </h:panelGrid>  
                                        </p:rowExpansion>

                                    </p:dataTable>  

                                    <p:dialog header="View Warehouse Inventory" modal="true" widgetVar="inventoryDialog" resizable="false"  
                                              width="900" showEffect="blind" hideEffect="blind">  

                                        <center>

                                            <h:panelGrid id="chooseWarehouse" columns="3" style="font-family:Tahoma;font-size:11px" >
                                                <h:outputText value="Choose Inventory"/>
                                                <h:outputText value=":"/>
                                                <h:selectOneMenu id="chooseInventoryType" value="#{WarehouseManagedBean.inventoryType}">
                                                    <f:selectItem itemLabel="Select Inventory Type" itemValue=""/>
                                                    <f:selectItem itemLabel="Products" itemValue="P"/>
                                                    <f:selectItem itemLabel="Materials" itemValue="M"/>
                                                    <p:ajax update="inventoryTable" 
                                                            listener="#{WarehouseManagedBean.handleInventoryTypeChange}"/>
                                                </h:selectOneMenu>

                                            </h:panelGrid>

                                            <p:dataTable id="inventoryTable" value="#{WarehouseManagedBean.inventoryList}"
                                                         var="inv" paginator="true" rows="15"
                                                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  

                                                         rowsPerPageTemplate="15,20,25" style="font-family:Tahoma;font-size:11px;width:100%"                      
                                                         emptyMessage="No data found with given criteria" widgetVar="inventoryTable"> 


                                                <f:facet name="header">                           
                                                    <p:outputPanel style="text-align:right"  >
                                                        <h:outputText value="Search all fields:"/>  
                                                        <p:inputText id="globalFilter" onkeyup="inventoryTable.filter()" style="right:-100px;width:150px" />  
                                                    </p:outputPanel>
                                                </f:facet>


                                                <p:column headerText="Batch ID" sortBy="#{inv.batchId}" filterBy="#{inv.batchId}"
                                                          filterStyle="width:60px" filterMatchMode="contains">
                                                    <h:outputText value="#{inv.batchId}"/>
                                                </p:column>

                                                <p:column headerText="Item ID"  sortBy="#{inv.itemId}" filterBy="#{inv.itemId}" 
                                                          filterStyle="width:60px" filterMatchMode="contains" style="border-left-color:transparent;border-right-color:transparent">   
                                                    <h:outputText value="#{inv.itemId}" />
                                                </p:column>


                                                <p:column headerText="Item Name" sortBy="#{inv.name}" filterBy="#{inv.name}" 
                                                          filterStyle="width:160px" filterMatchMode="contains" style="border-left-color:transparent;border-right-color:transparent">  

                                                    <h:outputText value="#{inv.name}" />  

                                                </p:column>  


                                                <p:column headerText="In Hand Quantity" sortBy="#{inv.inHandQty}" filterBy="#{inv.inHandQty}" filterMatchMode="contains" 
                                                          filterStyle="width:60px" style="border-left-color:transparent;border-right-color:transparent">  

                                                    <h:outputText value="#{inv.inHandQty}" />  

                                                </p:column>  


                                                <p:column headerText="Reserved Quantity" sortBy="#{inv.reservedQty}" filterBy="#{inv.reservedQty}" 
                                                          filterStyle="width:60px" filterMatchMode="contains" style="border-left-color:transparent;border-right-color:transparent">  

                                                    <h:outputText value="#{inv.reservedQty}" />  
                                                </p:column>  

                                                <p:column>
                                                    <p:commandButton  image="ui-icon ui-icon-trash"
                                                                      ajax="true"  update="panel"
                                                                      onclick="entrydialog.show()">
                                                        <f:setPropertyActionListener value="#{inv}" target="#{WarehouseManagedBean.selectedUnhousedInventory}"/>
                                                    </p:commandButton>
                                                </p:column>

                                            </p:dataTable>
                                        </center>
                                    </p:dialog>

                                    <p:dialog  showEffect="blind" hideEffect="blind" modal="true"
                                               header="Discard Inventory Batch " width="800"  widgetVar="entrydialog">  
                                        <center>


                                            <h:outputText value="Remarks" style="font-family:Tahoma;font-size: 12px"/>
                                            <h:outputText value=":"/>
                                            <p:inputTextarea style="width:200px;height:100px" value="#{WarehouseManagedBean.remarks}"/>

                                            <p:commandButton value="Discard" update="panel growl" ajax="true" oncomplete="entrydialog.hide()"  
                                                             actionListener="#{WarehouseManagedBean.discardInventoryBatch}" />  
                                            <p:commandButton value="Cancel" onclick="entrydialog.hide()" type="button" />   
                                        </center>
                                    </p:dialog> 


                                    <!--DIALOG FOR DELETING A  SINGLE ROW-->
                                    <p:confirmDialog message="Are you sure you want to delete this warehouse?"  
                                                     showEffect="blind" hideEffect="blind" modal="true" 
                                                     header="Delete Warehouse" severity="alert" widgetVar="warehouseDialog">  
                                        <center>
                                            <p:commandButton value="Yes" update="panel" ajax="true" immediate="true" oncomplete="warehouseDialog.hide()"  
                                                             actionListener="#{WarehouseManagedBean.deleteWarehouse}" />  
                                            <p:commandButton value="No" onclick="warehouseDialog.hide()" type="button" />   
                                        </center>

                                    </p:confirmDialog>  


                                    <p:ajaxStatus style="width:16px;height:16px;">  
                                        <f:facet name="start">  
                                            <h:graphicImage value="25(2).gif" />  
                                        </f:facet>  

                                        <f:facet name="complete">  
                                            <h:outputText value="" />  
                                        </f:facet>  
                                    </p:ajaxStatus>
                                </td>
                            </tr>

                            <tr></tr>
                        </table>

                        <p:dialog header="Warehouse Detail" widgetVar="editDialog" resizable="false"  
                                  width="800" showEffect="blind" hideEffect="blind">  
                            <center>
                                <h:panelGrid id="display1" columns="3" cellpadding="4" style="font-family:Tahoma; font-size:12px">  


                                    <h:outputText value="Product Id" />  
                                    <h:outputText value=":"/>
                                    <h:outputText value="#{WarehouseManagedBean.selectedViewWarehouse.id}" />  

                                    <h:outputText value="Product Name" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{WarehouseManagedBean.selectedViewWarehouse.name}" style="font-weight:bold" rendered="#{!WarehouseManagedBean.editMode}"/>  
                                        <p:inputText value="#{WarehouseManagedBean.selectedViewWarehouse.name}" rendered="#{WarehouseManagedBean.editMode}" label="Product Name"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="Street Address" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{WarehouseManagedBean.selectedViewWarehouse.street}" style="font-weight:bold" rendered="#{!WarehouseManagedBean.editMode}"/>  
                                        <p:inputText value="#{WarehouseManagedBean.selectedViewWarehouse.street}" rendered="#{WarehouseManagedBean.editMode}" label="Description"/>                            
                                    </h:panelGroup>  

                                    <h:outputText value="City"/> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{WarehouseManagedBean.selectedViewWarehouse.city}" style="font-weight:bold" rendered="#{!WarehouseManagedBean.editMode}"/>  
                                        <p:inputText value="#{WarehouseManagedBean.selectedViewWarehouse.city}" rendered="#{WarehouseManagedBean.editMode}" label="Shelf Life"/>  
                                    </h:panelGroup>  

                                    <h:outputText value="Country" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{WarehouseManagedBean.selectedViewWarehouse.country}" style="font-weight:bold" rendered="#{!WarehouseManagedBean.editMode}"/>  
                                        <p:inputText value="#{WarehouseManagedBean.selectedViewWarehouse.country}" rendered="#{WarehouseManagedBean.editMode}" label="Case Weight"/>  
                                    </h:panelGroup> 

                                    <h:outputText value="Postal Code" /> 
                                    <h:outputText value=":"/>
                                    <h:panelGroup>  
                                        <h:outputText value="#{WarehouseManagedBean.selectedViewWarehouse.postcode}" style="font-weight:bold" rendered="#{!WarehouseManagedBean.editMode}"/>  
                                        <p:inputText value="#{WarehouseManagedBean.selectedViewWarehouse.postcode}" rendered="#{WarehouseManagedBean.editMode}" required="true" label="Last Name"/>  
                                    </h:panelGroup> 

                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>
                                    <h:outputText value=""/>

                                    <h:outputText value=""/>
                                    <h:outputText value=""/>

                                    <p:outputPanel rendered="#{WarehouseManagedBean.editMode}" layout="block" style="text-align:right">  
                                        <p:commandButton value="Save" update="panel" actionListener="#{WarehouseManagedBean.editWarehouse}"   
                                                         oncomplete="editDialog.hide()" image="ui-icon ui-icon-check" />  
                                        <p:commandButton value="Cancel" onclick="editDialog.hide()" type="button" image="ui-icon ui-icon-close"/>  
                                    </p:outputPanel>  


                                </h:panelGrid>  
                            </center>
                        </p:dialog>  

                        <p:dialog header="Delete Selected Records" modal="true" widgetVar="deleteDialog">

                            <h:outputText value="You are about to permanently delete records." /><br /><br />
                            <h:outputText value="Are you sure you want to continue?" /><br /><br/>

                            <center>
                                <p:commandButton value="Yes" ajax="true" immediate="true" update="panel" 
                                                 oncomplete="deleteDialog.hide()" actionListener="#{WarehouseManagedBean.deletewarehouses}" />
                                <p:commandButton value="No" oncomplete="deleteDialog.hide()" /> 

                            </center>
                        </p:dialog>


                    </div>

                    <div id="bottom" class="bottom">
                        <h:graphicImage value="/image/merlionfooter.jpg"/>
                    </div>
                </h:form>
            </h:body>
        </f:view>
    </f:view>
</html>
